﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for UrlReriteHandler
/// </summary>
public class UrlRewriteHandler
{
    HttpRequest m_request = null;
    public UrlRewriteHandler(HttpRequest request)
    {
        //
        // TODO: Add constructor logic here
        //
        m_request = request;
    }

    /// <summary>
    /// Rewrites the request URL.
    /// </summary>
    /// <returns></returns>
    /// <Author>Tecky Lee</Author>
    /// <Date>2011/5/9 16:47</Date>
    public string RewriteRequestUrl()
    {

        String path = m_request.Url.LocalPath;
        string newPath = string.Empty;

        Regex reg = new Regex("(.*)/default/([^/]*)", RegexOptions.IgnoreCase);

        //产品编号重写
        if (reg.IsMatch(path))
        {
            Match match = reg.Match(path);
            newPath = match.Groups[1].Value+ "/default.aspx?id=" + match.Groups[2].Value;
        }
        else
        {
            
            newPath = path;
        }
        
        return newPath;
    }
}